package com.zrwl.poscloud.admin.restapi.baseInfo;
import com.zrwl.poscloud.base.entity.Admin;
import com.zrwl.poscloud.base.entity.User;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.xo.vo.AdminVO;
import com.zrwl.poscloud.xo.vo.EmployeeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.UserService;
import com.zrwl.poscloud.xo.vo.UserVO;

/**
 * 用户信息 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-02-24
 */
@RestController
@Api(value = "用户信息相关接口", tags = {"用户信息相关接口"})
@RequestMapping("/user")
@Slf4j
public class UserRestApi {
    @Autowired
    private UserService userService;

    @AuthorityVerify
    @ApiOperation(value = "获取用户信息列表", notes = "获取用户信息列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserVO userVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户信息列表: {}", userVO);
        return ResultUtil.successWithData(userService.getPageList(userVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取用户信息列表", notes = "获取用户信息列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody UserVO userVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户信息列表: {}", userVO);
        return ResultUtil.successWithData(userService.getAllList(userVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "通过昵称和登录账号或手机号获取取用户信息", notes = "通过昵称和登录账号或手机号获取取用户信息", response = String.class)
    @PostMapping("/getUserMesByNickNameAndUserNameOrMobile")
    public String getUserMesByNickNameAndUserNameOrMobile(@Validated({GetList.class}) @RequestBody UserVO userVO, BindingResult result){
        ThrowableUtils.checkParamArgument(result);
        log.info("通过昵称和登录账号或手机号获取取用户信息: {}", userVO);
        return ResultUtil.successWithData(userService.getUserMesByNickNameAndUserNameOrMobile(userVO));
    }
    @AuthorityVerify
    @OperationLogger(value = "新增用户信息")
    @ApiOperation(value = "新增用户信息", notes = "新增用户信息", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserVO userVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增用户信息: {}", userVO);
        return userService.add(userVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改用户信息")
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserVO userVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改用户信息: {}", userVO);
        return userService.edit(userVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除用户信息")
    @ApiOperation(value = "删除用户信息", notes = "删除用户信息", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody UserVO userVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除用户信息: {}", userVO);
        return userService.delete(userVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "重置用户密码")
    @ApiOperation(value = "重置用户密码", notes = "重置用户密码", response = String.class)
    @PostMapping("/resetUserPassword")
    public String resetUserPassword(@Validated({Delete.class}) @RequestBody UserVO userVO, BindingResult result) {
        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("重置用户密码: {}", userVO);
        return userService.resetUserPassword(userVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "根据手机号获取用户")
    @ApiOperation(value = "根据手机号获取用户", notes = "根据手机号获取用户")
    @PostMapping("/getUserByMobile")
    public String userByMobile(@Validated({GetList.class}) @RequestBody UserVO userVO, BindingResult result) {
        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        return ResultUtil.successWithData(userService.getUserByMobile(userVO.getMobile()));
    }
}
